﻿using MarzTargetCode;
using SFML.Graphics;
using SFML.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MarzTargetCode
{
    class Functions
    {
        public static RenderWindow window;
        public static Font f;
        /// <summary>
        /// Draws a rectangle
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="size"></param>
        /// <param name="texture"></param>
        public static void DrawRectangle(Coord pos, Coord size, string texture)
        {
            if (texture != string.Empty)
            {
                Image im = new Image(texture);
                Texture t = new Texture(im);
                window.Draw(new RectangleShape() { Position = new Vector2f((float)pos.X, (float)pos.Y), Size = new Vector2f((float)size.X, (float)size.Y), Texture = t });
            }
            else
                window.Draw(new RectangleShape() { Position = new Vector2f((float)pos.X, (float)pos.Y), Size = new Vector2f((float)size.X, (float)size.Y) });
        }

        /// <summary>
        /// Draws a circle
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="radius"></param>
        /// <param name="texture"></param>
        public static void DrawCircle(Coord pos, double radius, string texture)
        {
            if (texture != string.Empty)
            {
                Image im = new Image(texture);
                Texture t = new Texture(im);
                window.Draw(new CircleShape() { Position = new Vector2f((float)pos.X, (float)pos.Y), Radius = (float)radius, Texture = t });
            }
            else
                window.Draw(new CircleShape() { Position = new Vector2f((float)pos.X, (float)pos.Y), Radius = (float)radius });
        }
        /// <summary>
        /// Draws the input text
        /// </summary>
        /// <param name="str"></param>
        static public void PrintText(Coord pos, string str, int size)
        {

            Text t = new Text() { DisplayedString = str, CharacterSize = (uint)size, Font = f, Position = new Vector2f((float)pos.X, (float)pos.Y) };
            window.Draw(t);

        }

        static public bool IsColliding(Coord xPos, Coord xSize, Coord yPos, Coord ySize)
        {
            RectangleShape x = new RectangleShape(new Vector2f((float)xSize.X, (float)xSize.Y));
            x.Position = new Vector2f((float)xPos.X, (float)xPos.Y);
            RectangleShape y = new RectangleShape(new Vector2f((float)ySize.X, (float)ySize.Y));
            y.Position = new Vector2f((float)yPos.X, (float)yPos.Y);

            return x.GetGlobalBounds().Intersects(y.GetGlobalBounds());
        }

    }
}
